package com.lipy.springootrabbitmq.controller;

import com.lipy.springootrabbitmq.config.RabbitMQConfig;
import com.lipy.springootrabbitmq.config.deadLetter.DeadLetterSender;
import com.lipy.springootrabbitmq.config.fanout.FanoutSender;
import com.lipy.springootrabbitmq.config.manage.ManageSender;
import com.lipy.springootrabbitmq.config.object.ObjectSender;
import com.lipy.springootrabbitmq.config.topic.TopicSender;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;

/**
 * @description:
 * @author: lipy
 * @create: 2020-09-22 23:00
 **/
@RestController
@RequestMapping("/demo")
public class DemoController {

    @Autowired
    RabbitTemplate rabbitTemplate;

    @Autowired
    FanoutSender fanoutSender;
    @GetMapping("fanout")
    public String fanout(){
        System.out.println("fanoutSender = " + fanoutSender);
        fanoutSender.send();
        return "ok";
    }
    @GetMapping("test")
    public String test(){
        System.out.println("DemoController.test");
        return "ok";
    }
    @Autowired
    ManageSender manageSender;
    @GetMapping("manage")
    public String manage(){
        manageSender.send();
        return "ok";
    }
//
    @Autowired
    ObjectSender objectSender;
    @GetMapping("object")
    public Object obect(){
        objectSender.send();
        return LocalDateTime.now();
    }

    @Autowired
    TopicSender topicSender;
    @GetMapping("topic/{key}")
    public Object topic(@PathVariable(value = "key") String key){
        if("A".equals(key)){
            topicSender.sendA();
        }else if("B".equals(key)){
            topicSender.sendB();
        }else {
            topicSender.sendB();
        }
        return LocalDateTime.now();
    }
    @Autowired
    DeadLetterSender deadLetterSender;
    @GetMapping("dead")
    public Object dead(){
        deadLetterSender.send();
        return "dead";
    }

    @GetMapping("none")
    public Object none(){
        rabbitTemplate.convertAndSend("noneex","nonerou","nonemsg");
        return "none";
    }
}
